<?php
class Jpenjualan extends CI_Controller{
    private $limit = 10;
    function  __construct() {
        parent::__construct();
        $this->load->model('Jpenjualan_model');
	$this->load->helper(array('form', 'url'));
	$this->load->library('form_validation');
      }

	function index($offset=''){

         $this->load->library('pagination'); //load library pagination
		$uri_segment = 3;
		$offset = $this->uri->segment($uri_segment);

		$config['base_url'] = site_url('jpenjualan/index/');
		$config['total_rows'] = $this->Jpenjualan_model->countData();
		$config['per_page'] = $this->limit;
		$config['num_links'] = 2;
		$config['full_tag_open'] = '<div id="pagination">';
		$config['full_tag_close'] = '</div>';

		$this->pagination->initialize($config);
		$data['pagination'] = $this->pagination->create_links();
		$data['offset']=$offset;
		$data['jumlah_data']=$this->Jpenjualan_model->countData();

		$data['jenis_penjualan']	= $this->Jpenjualan_model->get_list_data($this->limit,$offset)->result();

	//$data['jenis_penjualan'] = $this->Jpenjualan_model->getJpenjualan();

        $this->load->view('admin_views/jpenjualan/jpenjualan', $data);
    }

	function add()
	{
//		$this->form_validation->set_rules('strkode_penjualan', 'Kode Penjualan', 'trim|required|xss_clean');
		$this->form_validation->set_rules('strnama_jpenjualan', 'Jenis Penjualan', 'trim|required|xss_clean');

		$this->form_validation->set_message('required', ' %s tidak boleh kosong !!');

		if ($this->form_validation->run() == FALSE)
		 {
                       $this->load->view('admin_views/jpenjualan/add');
		}else{

                        $this->Jpenjualan_model->insert($_POST);
			redirect('jpenjualan/jpenjualan');
                }
	}

      function edit($intid_jpenjualan)
		{
			if($_POST==NULL)
			{

				$datajpenjualan = $this->Jpenjualan_model->select($intid_jpenjualan);
				foreach ($datajpenjualan as $g)
				{
					$data['intid_jpenjualan']	= $g->intid_jpenjualan;
//					$data['strkode_penjualan'] 	= $g->strkode_penjualan;
					$data['strnama_jpenjualan']	= $g->strnama_jpenjualan;
				}
				$this->load->view('admin_views/jpenjualan/edit', $data);
			}else {
				$this->Jpenjualan_model->update($intid_jpenjualan);
				redirect('jpenjualan/index');
			}

		}


    function delete($intid_jpenjualan)
	{
		$this->Jpenjualan_model->delete($intid_jpenjualan);
		redirect('jpenjualan/jpenjualan');
	}

}
?>
